<template>
  <div class="adminSet">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="菜单名称：" prop="resourceName">
        <el-input v-model="ruleForm.resourceName"></el-input>
      </el-form-item>
      <el-form-item label="排序号：" prop="resourceNumber">
        <el-input
          v-model="ruleForm.resourceNumber"
          onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
        ></el-input>
      </el-form-item>

      <el-form-item label="菜单路径" prop="resourceUrl">
        <el-input v-model="ruleForm.resourceUrl"></el-input>
      </el-form-item>
      <el-form-item label="菜单说明">
        <el-input type="textarea" v-model="ruleForm.resContent" style=" width: 80%;"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')" size="mini">保存</el-button>

        <el-button @click="resetForm('ruleForm')" size="mini">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { addmenus, changemenus } from "@/api/platformmanage";
import qs from "qs";
export default {
  data() {
    return {
      radio: "1",
      ifMain: "0",
      isRight: "0",

      ruleForm: {
        resourceReq: "",
        resourceUrl: "",
        resourceName: "",
        menuId: "",
        upMenuId: "",
        resourceDesc: "",
        upResourceReq: "",
        resourceNumber: ""
      },
      rules: {
        resourceName: [
          { required: true, message: "请输入菜单名称", trigger: "blur" }
        ]
        // resourceNumber: [
        //   { required: true, message: "请输入排序号", trigger: "blur" }
        // ],
        // resourceUrl: [
        //   { required: true, message: "请输入菜单路径", trigger: "blur" }
        // ]

        // password: [{ required: true }]
      }
    };
  },
  mounted() {
    console.log("lll");
    console.log(this.$route.params, "ppp");
    if (this.$route.params.button === 0) {
      this.ruleForm.resourceName = this.$route.params.v.resourceName;

      this.ruleForm.resourceLevel = this.$route.params.v.resourceLevel;

      this.ruleForm.resourceUrl = this.$route.params.v.resourceUrl;
      this.ruleForm.resourceNumber = this.$route.params.v.resourceNumber;
    }
  },
  methods: {
    resetForm() {
      this.$router.push("/menuManagement");
    },
    submitForm() {
      if (this.$route.params.button === 1) {
        if (
          this.ruleForm.resourceName == "" ||
          this.ruleForm.resourceName == null
        ) {
          this.$message.error("请输入菜单名称");
          return;
        }
        if (
          this.ruleForm.resourceUrl == "" ||
          this.ruleForm.resourceUrl == null
        ) {
          this.$message.error("请输入菜单路径");
          return;
        }
        this.ruleForm.upMenuId = this.$route.params.v.menuId;
        console.log(this.$route.params.v.resourceReq, "ooo");
        addmenus(this.ruleForm).then(res => {
          this.$message({
            showClose: true,
            message: "菜单信息添加成功",
            type: "success"
          });
          this.$router.push("/menuManagement");
        });
      } else if (this.$route.params.button === 0) {
        this.ruleForm.upMenuId = this.$route.params.v.upMenuId;
        this.ruleForm.menuId = this.$route.params.v.menuId;
        console.log(this.$route.params, "ppppp");
        changemenus(this.ruleForm).then(res => {
          this.$message({
            showClose: true,
            message: "菜单信息修改成功",
            type: "success"
          });
          this.$router.push("/menuManagement");
        });
        console.log("oo");
      } else if (this.$route.params.button === 2) {
        // this.ruleForm.upMenuId = this.$route.params.v.menuId;
        // this.ruleForm.menuId = this.$route.params.v.menuId;
        // console.log(this.$route.params, "ppppp");
        if (
          this.ruleForm.resourceName == "" ||
          this.ruleForm.resourceName == null
        ) {
          this.$message.error("请输入菜单名称");
          return;
        }
        // if (
        //   this.ruleForm.resourceUrl == "" ||
        //   this.ruleForm.resourceUrl == null
        // ) {
        //   this.$message.error("请输入菜单路径");
        //   return;
        // }
        addmenus(this.ruleForm).then(res => {
          this.$message({
            showClose: true,
            message: "菜单信息添加成功",
            type: "success"
          });
          this.$router.push("/menuManagement");
        });
        console.log("oo");
      }
    }
  }
};
</script>>

<style lang="less" scoped>
.adminSet {
  border: 1px solid #ebeef5;
  margin-left: 150px;
  padding: 50px 0px 20px 150px;
  width: 55%;
}
.el-input {
  position: relative;
  font-size: 14px;
  display: inline-block;
  width: 62%;
}
</style>
